package com.example.experiment4.dao;

import com.example.experiment4.domain.Person;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface PersonDao extends JpaRepository<Person, Integer> {

    @Query(value = "insert into person(name,address,phone) values (?,?,?)",nativeQuery = true)
    @Modifying
    @Transactional
    public Integer insertData(String name,String address,String phone);

    @Query(value = "select count(distinct name) from  person ",nativeQuery = true)
    public Integer countPersonByName();

    @Query(value = "select count(distinct phone) from  person",nativeQuery = true)
    public Integer countPersonByPhone();

    @Query(value = "select count(distinct phone) from  person where phone is not null and address is not null",nativeQuery = true)
    public Integer countPersonByPhoneAndAddress();
}
